<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="更新定时任务">
    </el-page-header>
    <div class="model-content">
      <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="任务名称" size="mini" prop="name">
              <el-input v-model="form.name" name="name">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="任务别名" size="mini" prop="aliasName">
              <el-input v-model="form.aliasName" name="aliasName">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="记录类型" size="mini" prop="recordType">
              <el-input v-model="form.recordType" name="recordType">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="cron表达式" size="mini" prop="cronExpression">
              <sc-cron v-model="form.cronExpression" placeholder="请输入Cron定时规则" clearable :shortcuts="shortcuts"></sc-cron>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="是否异步" size="mini" prop="isSync">
              <el-input v-model="form.isSync" name="isSync">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="任务url" size="mini" prop="url">
              <el-input v-model="form.url" name="url">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="任务备注" size="mini" prop="remark">
              <el-input v-model="form.remark" name="remark" type="textarea"></el-input>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="任务内容" size="mini" prop="content">
              <el-input v-model="form.content" name="content" type="textarea"></el-input>
            </el-form-item>

          </el-col>

          <el-col :span="22">
            <el-form-item>
              <el-button @click="goBack">取消</el-button>
              <el-button type="primary" @click="updateData">确定</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import common from "@/mixins/common.js";
import scCron from "@/components/scCron/index.vue";


export default {
  name: "schedulingTask_update",
  mixins: [common],
  components: {scCron},
  data() {
    return {
      form: {
        name: '',
        aliasName: '',
        recordType: '',
        cronExpression: '',
        isSync: '',
        url: '',
        remark: '',
        content: ''
      },
      shortcuts: [
        {
          text: "每天8点和12点 (自定义追加)",
          value: "0 0 8,12 * * ?"
        }
      ],
      rules: {
        name: [
          {required: true, message: '请输入任务名称', trigger: 'blur'}
        ],
        cronExpression: [
          {required: true, message: '请输入cron表达式', trigger: 'blur'}
        ],
        url: [
          {required: true, message: '请输入任务url', trigger: 'blur'}
        ],
      }
    }
  },
  async mounted() {
    let id = this.$route.query.id;
    let data = {};
    data.id = id;
    let res = await this.$http.form("/schedulingTask/view", data);
    if (res.code === 200) {
      this.form = res.data;
    }
  },
  methods: {
    async updateData() {
      try {
        let valid = await this.$refs["ruleForm"].validate();
        if (!valid) {
          return;
        }
      } catch (e) {
        return;
      }
      await this.updateDataPost();
    },
    async updateDataPost() {
      let res = await this.$http.form("/schedulingTask/update", this.form);
      if (res.code !== 200) {
        this.$message.error(res.msg);
        return
      }
      this.$message({
        message: '更新数据成功',
        type: 'success'
      });
      this.$router.go(-1);
    },

  }
}


</script>

<style scoped>

</style>
